﻿
using System;
namespace EasyComm.ServiceUnit
{
    public class AdminServiceUnitCollection<TContract> : ThreadSafeCollection<AdminServiceUnit<TContract>>
        where TContract : class
    {
        public virtual AdminServiceUnit<TContract> this[Uri uri]
        {
            get
            {
                base.InnerLock.EnterReadLock();
                try
                {
                    foreach (AdminServiceUnit<TContract> unit in this)
                    {
                        if (unit.ListenUri == uri)
                        {
                            return unit;
                        }
                    }
                    return null;
                }
                finally
                {
                    base.InnerLock.ExitReadLock();
                }
            }
        }

        //public virtual List<AdminServiceUnit<TContract>> this[ServiceContract contract]
        //{
        //    get
        //    {
        //        base.InnerLock.EnterReadLock();
        //        try
        //        {
        //            List<AdminServiceUnit<TContract>> unitList = new List<AdminServiceUnit<TContract>>();
        //            foreach (AdminServiceUnit<TContract> unit in this)
        //            {
        //                foreach (ServiceContract innerContract in unit.Contracts)
        //                {
        //                    if (innerContract.Equals(contract))
        //                    {
        //                        unitList.Add(unit);
        //                    }
        //                }
        //            }
        //            return unitList;
        //        }
        //        finally
        //        {
        //            base.InnerLock.ExitReadLock();
        //        }
        //    }
        //}
    }
}
